#!/bin/bash

# 设置仓库目录
REPO_DIR="."
REMOTE_REPO="https://github.com/yyned2501/blackjack_server.git"
REMOTE_BRANCH="master"

# 检查是否是一个 Git 仓库
if [ ! -d ".git" ]; then
    echo "Initializing Git repository in $REPO_DIR..."
    git init
    git remote add origin "$REMOTE_REPO"
    git fetch origin >/dev/null
    git reset --hard origin/"$REMOTE_BRANCH"
    git pull origin "$REMOTE_BRANCH"
fi
while true; do
    git fetch origin >/dev/null
    if [ $(git rev-list --count --right-only HEAD...origin/"$REMOTE_BRANCH") -gt 0 ]; then
        echo "Remote is ahead of local, there are updates."
        git reset --hard origin/"$REMOTE_BRANCH"
        git pull origin "$REMOTE_BRANCH"
        supervisorctl restart main
    fi
    sleep 60
done
